package com.quanshu.shop.goods.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.android.flexbox.AlignItems;
import com.google.android.flexbox.FlexDirection;
import com.google.android.flexbox.FlexWrap;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.quanshu.exchange.R;
import com.quanshu.shop.goods.entity.GoodsPropertyEntity;

import java.util.List;

/**
 * 作者  李哲
 * 创建时间 2018/7/26
 * 邮箱 lizhetongliao@163.com
 * 说明
 **/
public class GoodsPropetyAdapter extends BaseQuickAdapter<GoodsPropertyEntity, BaseViewHolder> {
    private Context mContext;
    private OnGoodsDialogclickListenner onGoodsDialogclickListenner;

    public GoodsPropetyAdapter(Context mContext, @Nullable List<GoodsPropertyEntity> data) {
        super(R.layout.item_goods_propety, data);
        this.mContext = mContext;
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsPropertyEntity item) {
        helper.setText(R.id.item_property_txt, item.getName());
        FlexboxLayoutManager flexboxLayoutManager = new FlexboxLayoutManager(mContext);
        flexboxLayoutManager.setFlexWrap(FlexWrap.WRAP);
        flexboxLayoutManager.setFlexDirection(FlexDirection.ROW);
        flexboxLayoutManager.setAlignItems(AlignItems.STRETCH);
        RecyclerView recyclerView = helper.getView(R.id.item_property_rl);
        recyclerView.setLayoutManager(flexboxLayoutManager);
        GoodsPropertyChildAdapter goodsPropertyChildAdapter = new GoodsPropertyChildAdapter(mContext, item.getStringList());
        goodsPropertyChildAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                if (onGoodsDialogclickListenner != null) {
                    onGoodsDialogclickListenner.onclickPosition(helper.getLayoutPosition(), position);
                }
            }
        });
        recyclerView.setAdapter(goodsPropertyChildAdapter);
        //helper.addOnClickListener(R.id.item_property_rl);
    }

    public void setOndialogOnclickListener(OnGoodsDialogclickListenner ondialogOnclickListener1) {
        onGoodsDialogclickListenner = ondialogOnclickListener1;
    }

    public interface OnGoodsDialogclickListenner {
        void onclickPosition(int parentPosition, int childPosition);
    }

}
